﻿#ifndef PST_ANIMATIONTOOBARINFODATA_H
#define PST_ANIMATIONTOOBARINFODATA_H

#include <QObject>
#include <QDomElement>
#include <QDomDocument>
#include <QDomNodeList>
#include "BaseModule/GlobalHelper.h"

namespace pst
{
    class AnimationTooBarInfoData : public QObject
    {
        Q_OBJECT
    public:
        AnimationTooBarInfoData(QObject* parent = nullptr) :QObject(parent) {}

        void setType(const QString& type) { m_type = type; }
        QString getType() { return m_type; }

        void setUnit(const QString& unit) { m_unit = unit; }
        QString getUnit() { return m_unit; }

        void setCurrentValue(const QString value) { m_currentValue = value; }
        QString getCurrentValue() { return m_currentValue; }

        void setSliderCurrentValue(int value) { m_sliderCurrentValue = value; }
        int getSliderCurrentValue() { return m_sliderCurrentValue; }

        void setSliderMaxValue(int value) { m_sliderMaxValue = value; }
        int getSliderMaxValue() { return m_sliderMaxValue; }

        /// @brief 文件写出至工程文件
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso = false)
        {
            QDomElement _AnimationSettingDataRoot = doc->createElement("AnimationTooBarInfoData");

            GlobalHelperInstance->createDomElement(doc, &_AnimationSettingDataRoot, "Type", m_type);
            GlobalHelperInstance->createDomElement(doc, &_AnimationSettingDataRoot, "Unit", m_unit);
            GlobalHelperInstance->createDomElement(doc, &_AnimationSettingDataRoot, "CurrentValue", m_currentValue);
            GlobalHelperInstance->createDomElement(doc, &_AnimationSettingDataRoot, "SliderCurrentValue", QString::number(m_sliderCurrentValue));
            GlobalHelperInstance->createDomElement(doc, &_AnimationSettingDataRoot, "SliderMaxValue", QString::number(m_sliderMaxValue));

            element->appendChild(_AnimationSettingDataRoot);

            return _AnimationSettingDataRoot;
        }
        /// @brief 从工程文件读入数据
        void readFromProjectFile(QDomElement* element, bool isdiso = false)
        {
            m_type = element->elementsByTagName("Type").at(0).toElement().text();
            m_unit = element->elementsByTagName("Unit").at(0).toElement().text();
            m_currentValue = element->elementsByTagName("CurrentValue").at(0).toElement().text();
            m_sliderCurrentValue = element->elementsByTagName("SliderCurrentValue").at(0).toElement().text().toInt();
            m_sliderMaxValue = element->elementsByTagName("SliderMaxValue").at(0).toElement().text().toInt();
        }

    private:
        QString m_type{};
        QString m_unit{};
        QString m_currentValue{};
        int m_sliderCurrentValue{0};
        int m_sliderMaxValue{1};
    };
}
#endif
